//
//  HYFAccount.m
//  MyOCWeibo
//
//  Created by 黄勇锋 on 16/10/6.
//  Copyright © 2016年 黄勇锋. All rights reserved.
//

#import "HYFAccount.h"

@implementation HYFAccount

- (instancetype)initWithDict:(NSDictionary *)dict{
    
    if (self = [super init]) {
        
        [self setValuesForKeysWithDictionary:dict];
    }
    
    return self;
}

+ (instancetype)accountWithDict:(NSDictionary *)dict{
    
    
    return [[self alloc]initWithDict:dict];
}


- (void)setAccess_token:(NSString *)access_token{
    
    _access_token = access_token;
    
    //是用来计算 accessToken 的过期时间的.再刚刚获取到 accessToken 的时候,记录这个时间是合适的.
    self.creatDate = [NSDate date];
}


#pragma mark - 归档
- (void)encodeWithCoder:(NSCoder *)aCoder{

    [aCoder encodeObject:self.access_token forKey:@"access_token"];
    [aCoder encodeInteger:self.expires_in forKey:@"expires_in"];
    [aCoder encodeInteger:self.remind_in forKey:@"remind_in"];
    [aCoder encodeInteger:self.uid forKey:@"uid"];
    [aCoder encodeObject:self.creatDate forKey:@"creatDate"];
}


#pragma mark - 解档
- (instancetype)initWithCoder:(NSCoder *)aDecoder{
    
    if (self = [super init]) {
        
        self.access_token = [aDecoder decodeObjectForKey:@"access_token"];
        self.expires_in = [aDecoder decodeIntegerForKey:@"expires_in"];
        self.remind_in = [aDecoder decodeIntegerForKey:@"remind_in"];
        self.uid = [aDecoder decodeIntegerForKey:@"uid"];
        self.creatDate = [aDecoder decodeObjectForKey:@"creatDate"];
        
    }

    return self;
}



@end
